package com.yeswater.redislock.lock;

import cn.hutool.core.util.IdUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

import java.util.concurrent.locks.Lock;

/**
 * @Description:
 * @author： yeswater
 * @create： 2024/6/30
 */

@Component
public class DistributedLockFactory
{
	@Autowired
	private StringRedisTemplate stringRedisTemplate;
	private String lockName;
	
	private String uuidValue;
	
	{
		this.uuidValue = IdUtil.simpleUUID();//UUID;
	}
	
	public Lock getDistributedLock(String lockType)
	{
		if(lockType == null) return null;
		
		if(lockType.equalsIgnoreCase("REDIS")){
			lockName = "RedisLock";
			return new RedisDistributedLock(stringRedisTemplate,lockName, uuidValue);
		} else if(lockType.equalsIgnoreCase("ZOOKEEPER")){
			//TODO zookeeper版本的分布式锁实现
			//return new ZookeeperDistributedLock();
			return  null;
		} else if(lockType.equalsIgnoreCase("MYSQL")){
			//TODO mysql版本的分布式锁实现
			//return new MySQLDistributedLock();
			return null;
		}
		
		return null;
	}
}
